import router  from "@/router";
import store from '@/store/index.js'
// 路由跳转前登录情况
router.beforeEach(async (to, from, next) => {
  let loginUser = store.state.userInfo;
  if (to.path==='/login/'||to.path==='/login'||to.path==='/chat'){
    next()
  }
  // 无登录信息
  if (loginUser.token === undefined){
    // 获取登录信息
    await store.dispatch("getLoginUser")
    loginUser = store.state.userInfo;
  }
  // 没有登录，跳转登录
  if (loginUser === null) {
    // 等登陆后再执行后续
    next(`/login/?redirect=${to.fullPath}`)
  }
  next();
});